package com.anjiplus.template.gaea.business.work.station.controller;

import com.anji.plus.gaea.bean.ResponseBean;
import com.anji.plus.gaea.curd.controller.BaseResponse;
import com.anjiplus.template.gaea.business.work.station.entity.Station;
import com.anjiplus.template.gaea.business.work.station.service.StationService;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 站点controller
 *
 * @author yxm
 */
@RestController
@RequestMapping("/station")
public class StationController extends BaseResponse {

    private StationService stationService;

    StationController(StationService stationService) {
        this.stationService = stationService;
    }

    /**
     * 查询全部站点列表
     *
     * @return
     */
    @GetMapping("/listAll")
    public ResponseBean listAll() {
        return responseSuccessWithData(stationService.listAll());
    }

    /**
     * 根据站点名称模糊查询站点列表
     *
     * @param name
     * @return
     */
    @GetMapping("/listByStationName/{name}")
    public ResponseBean listByStationName(@PathVariable String name) {
        return responseSuccessWithData(stationService.listByStationName(name));
    }

    /**
     * 添加站点
     *
     * @param station
     * @return
     */
    @PostMapping
    public ResponseBean add(@RequestBody Station station) {
        Map<String, Object> result = new HashMap<>();
        result.put("row", stationService.add(station));
        return responseSuccessWithData(result);
    }

    /**
     * 移除站点
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResponseBean remove(@PathVariable String id) {
        Map<String, Object> result = new HashMap<>();
        result.put("row", stationService.remove(id));
        return responseSuccessWithData(result);
    }

    /**
     * 修改站点
     *
     * @param station
     * @return
     */
    @PutMapping
    public ResponseBean update(@RequestBody Station station) {
        Map<String, Object> result = new HashMap<>();
        result.put("row", stationService.update(station));
        return responseSuccessWithData(result);
    }

}
